Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.518 lượt xem;
- ShowInfoOfPlayer.cs
- UtilityScripts /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3 using ExitGames.Client.Photon;
4 /// <summary>
5 /// Can be attached to a GameObject to show info about the owner of the PhotonView.
6 /// </summary>
7 /// <remarks>
8 /// This is a Photon.Monobehaviour, which adds the property photonView (that's all).
9 /// </remarks>
10 [RequireComponent(typeof(PhotonView))]
11 public class ShowInfoOfPlayer : Photon.MonoBehaviour
12 {
13 private GameObject textGo;
14 private TextMesh tm;
15 public float CharacterSize = 0;
16
17 public Font font;
18 public bool DisableOnOwnObjects;
19
20 void Start()
21 {
22 if (font == null)
23 {
24 #if UNITY_3_5
25 font = (Font)FindObjectsOfTypeIncludingAssets(typeof(Font))[0];
26 #else
27 font = (Font)Resources.FindObjectsOfTypeAll(typeof(Font))[0];
28 #endif
29 Debug.LogWarning("No font defined. Found font: " + font);
30 }
31
32 if (tm == null)
33 {
34 textGo = new GameObject("3d text");
35 //textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
36 textGo.transform.parent = this.gameObject.transform;
37 textGo.transform.localPosition = Vector3.zero;
38
39 MeshRenderer mr = textGo.AddComponent<MeshRenderer>();
40 mr.material = font.material;
41 tm = textGo.AddComponent<TextMesh>();
42 tm.font = font;
43 tm.anchor = TextAnchor.MiddleCenter;
44 if (this.CharacterSize > 0)
45 {
46 tm.characterSize = this.CharacterSize;
47 }
48 }
49 }
50
51 void Update()
52 {
53 bool showInfo = !this.DisableOnOwnObjects || this.photonView.isMine;
54 if (textGo != null)
55 {
56 textGo.SetActive(showInfo);
57 }
58 if (!showInfo)
59 {
60 return;
61 }
62
63
64 PhotonPlayer owner = this.photonView.owner;
65 if (owner != null)
66 {
67 tm.text = (string.IsNullOrEmpty(owner.name)) ? "player"+owner.ID : owner.name;
68 }
69 else if (this.photonView.isSceneView)
70 {
71 tm.text = "scn";
72 }
73 else
74 {
75 tm.text = "n/a";
76 }
77 }
78 }
2 using System.Collections;
3 using ExitGames.Client.Photon;
4 /// <summary>
5 /// Can be attached to a GameObject to show info about the owner of the PhotonView.
6 /// </summary>
7 /// <remarks>
8 /// This is a Photon.Monobehaviour, which adds the property photonView (that's all).
9 /// </remarks>
10 [RequireComponent(typeof(PhotonView))]
11 public class ShowInfoOfPlayer : Photon.MonoBehaviour
12 {
13 private GameObject textGo;
14 private TextMesh tm;
15 public float CharacterSize = 0;
16
17 public Font font;
18 public bool DisableOnOwnObjects;
19
20 void Start()
21 {
22 if (font == null)
23 {
24 #if UNITY_3_5
25 font = (Font)FindObjectsOfTypeIncludingAssets(typeof(Font))[0];
26 #else
27 font = (Font)Resources.FindObjectsOfTypeAll(typeof(Font))[0];
28 #endif
29 Debug.LogWarning("No font defined. Found font: " + font);
30 }
31
32 if (tm == null)
33 {
34 textGo = new GameObject("3d text");
35 //textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
36 textGo.transform.parent = this.gameObject.transform;
37 textGo.transform.localPosition = Vector3.zero;
38
39 MeshRenderer mr = textGo.AddComponent<MeshRenderer>();
40 mr.material = font.material;
41 tm = textGo.AddComponent<TextMesh>();
42 tm.font = font;
43 tm.anchor = TextAnchor.MiddleCenter;
44 if (this.CharacterSize > 0)
45 {
46 tm.characterSize = this.CharacterSize;
47 }
48 }
49 }
50
51 void Update()
52 {
53 bool showInfo = !this.DisableOnOwnObjects || this.photonView.isMine;
54 if (textGo != null)
55 {
56 textGo.SetActive(showInfo);
57 }
58 if (!showInfo)
59 {
60 return;
61 }
62
63
64 PhotonPlayer owner = this.photonView.owner;
65 if (owner != null)
66 {
67 tm.text = (string.IsNullOrEmpty(owner.name)) ? "player"+owner.ID : owner.name;
68 }
69 else if (this.photonView.isSceneView)
70 {
71 tm.text = "scn";
72 }
73 else
74 {
75 tm.text = "n/a";
76 }
77 }
78 }
Can be attached to a GameObject to show info about the owner of the PhotonView.
This is a Photon.Monobehaviour, which adds the property photonView (that's all).
textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);